using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EntityAttackCheck : MonoBehaviour
{
    private Entity entity;

    protected virtual void Awake()
    {
        entity = GetComponentInParent<Entity>();
    }

    //攻击和拼刀互斥     拼刀只产生一次，是玩家对敌人，当然双方都取消伤害
    protected virtual void OnTriggerEnter2D(Collider2D other)
    {
        // Debug.Log(this.name + "命中" + other);
        if (CheckEnemy(other))
        {
            entity.AttackTrigger(other);
        }
    }

    // todo 考虑改为阵营的判断
    // 注意在AttackTrigger还有一重判断
    private bool CheckEnemy(Collider2D other)
    {
        if (entity is Enemy)
            return other.gameObject.layer == LayerMask.NameToLayer("Player");

        if (entity is Player)
            return other.gameObject.layer == LayerMask.NameToLayer("Enemy");
        return false;
    }
}
